package class6;

/**
 * https://leetcode.cn/problems/complement-of-base-10-integer/
 * 十进制整数的反码
 */
public class Code04_BitwiseComplement {
    public static void main(String[] args) {
        int n = 10;
        int res = bitwiseComplement(n);
        System.out.println("res = " + res);
    }

    public static int bitwiseComplement(int n) {
        int num = 1;
        while (num < n) {
            num = (num << 1) + 1;
        }
        return num ^ n;
    }
}
